﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Stockholm.SOA.Kaskelot.WCF.ServiceContracts;
using Stockholm.SOA.Kaskelot.WCF.DataContracts;
using Kaskelot.SP.Core;
using System.ServiceModel;
using Stockholm.SOA.Kaskelot.WCF.FaultContracts;

namespace Kaskelot.SP.Services
{
	public class AdminService : BaseService<IKaskelotService>
	{
		#region Valkrets
		public IList<Valkrets> GetValkretsar()
		{
			IList<Valkrets> result = null;
			try
			{
				result = this.channel.GetValkretsar(ApplicationContext.Current.Val.Id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetValkretsar", "Error getting valkretsar", ex);
			}

			return result;
		}

		public Valkrets GetValkrets(Guid id)
		{
			Valkrets result = null;
			try
			{
				result = this.channel.GetValkrets(ApplicationContext.Current.Val.Id, id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetValkrets", "Error getting valkrets", ex);
			}
			return result;
		}

		public void CreateValkrets(Valkrets valkrets)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.CreateValkrets(valkrets);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreateValkrets", "Error creating valkrets", ex);
			}
		}

		public void UpdateValkrets(Valkrets valkrets)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.UpdateValkrets(valkrets);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateValkrets", "Error updating valkrets", ex);
			}
		}

		public void DeleteValkrets(Guid valkretsId)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.DeleteValkrets(ApplicationContext.Current.Val.Id, valkretsId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "DeleteValkrets", "Error deleting valkrets", ex);
				throw;
			}
		}
		#endregion

		#region Församling
		public IList<Forsamling> GetForsamlingar(Guid? valkretsId)
		{
			IList<Forsamling> result = null;
			try
			{
				result = this.channel.GetForsamlingar(ApplicationContext.Current.Val.Id, valkretsId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
                Logger.LogError(this, LayerNames.Services, "GetForsamlingar", "Error getting forsamlingar", ex);
			}

			return result;
		}

		public Forsamling GetForsamling(Guid id)
		{
			Forsamling result = null;
			try
			{
				result = this.channel.GetForsamling(ApplicationContext.Current.Val.Id, id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetForsamling", "Error getting forsamling", ex);
			}
			return result;
		}

		public void CreateForsamling(Forsamling forsamling)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.CreateForsamling(forsamling);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreateForsamling", "Error creating forsamling", ex);
			}
		}

		public void UpdateForsamling(Forsamling forsamling)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.UpdateForsamling(forsamling);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateForsamling", "Error updating forsamling", ex);
			}
		}

		public void DeleteForsamling(Guid forsamlingId)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.DeleteForsamling(ApplicationContext.Current.Val.Id, forsamlingId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "DeleteForsamling", "Error deleting forsamling", ex);
				throw;
			}
		}
		#endregion

		#region Valdistrikt
		public IList<Valdistrikt> GetValdistriktList(Guid? forsamlingId)
		{
			IList<Valdistrikt> result = null;
			try
			{
				result = this.channel.GetValdistriktList(ApplicationContext.Current.Val.Id, forsamlingId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
                Logger.LogError(this, LayerNames.Services, "GetValdistriktList", "Error getting valdistrikt", ex);
			}

			return result;
		}

		public Valdistrikt GetValdistrikt(Guid id)
		{
			Valdistrikt result = null;
			try
			{
				result = this.channel.GetValdistrikt(ApplicationContext.Current.Val.Id, id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetValdistrikt", "Error getting valdistrikt", ex);
			}
			return result;
		}

		public void CreateValdistrikt(Valdistrikt valdistrikt)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.CreateValdistrikt(valdistrikt);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreateValdistrikt", "Error creating valdistrikt", ex);
			}
		}

		public void UpdateValdistrikt(Valdistrikt valdistrikt)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.UpdateValdistrikt(valdistrikt);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateValdistrikt", "Error updating valdistrikt", ex);
			}
		}

		public void DeleteValdistrikt(Guid valdistriktId)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.DeleteValdistrikt(ApplicationContext.Current.Val.Id, valdistriktId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "DeleteValdistrikt", "Error deleting valdistrikt", ex);
				throw;
			}
		}
		#endregion

		#region Materiel
		public IList<MaterielTyp> GetMaterielTypList()
		{
			IList<MaterielTyp> result = null;

			try
			{
				result = this.channel.GetMaterielTypList(ApplicationContext.Current.Val.Id).OrderBy(mt => mt.Beskrivning).ToList();
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetMaterielTypList", "Error getting materieltyp list", ex);
			}

			return result;
		}

		public MaterielTyp GetMaterielTyp(Guid id)
		{
			MaterielTyp result = null;
			try
			{
				result = this.channel.GetMaterielTyp(ApplicationContext.Current.Val.Id, id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetMateriel", "Error getting materieltyp", ex);
			}
			return result;
		}

		public void CreateMaterielTyp(MaterielTyp materiel)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.CreateMaterielTyp(materiel);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreateMaterielTyp", "Error creating materieltyp", ex);
			}
		}

		public void UpdateMaterielTyp(MaterielTyp materiel)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.UpdateMaterielTyp(materiel);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateMaterielTyp", "Error updating materieltyp", ex);
			}
		}

		public void DeleteMaterielTyp(Guid materielId)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.DeleteMaterielTyp(ApplicationContext.Current.Val.Id, materielId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "DeleteMaterielTyp", "Error deleting materieltyp", ex);
				throw;
			}
		}

		public void SetUnderliggandeMaterielTyperForMaterielTyp(Guid parentId, IEnumerable<MaterielTypMaterielTyp> underliggandeTyper)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.SetUnderliggandeMaterielTyperForMaterielTyp(ApplicationContext.Current.Val.Id, parentId, underliggandeTyper);	
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "SetUnderliggandeMaterielTyp", "Error setting underliggande materieltyper", ex);
			}
		}

		public IEnumerable<MaterielTyp> GetUnderliggandeMaterielTyperForMaterielTyp(Guid parentId)
		{
			IList<MaterielTyp> result = new List<MaterielTyp>();
			try
			{
				result = this.channel.GetUnderliggandeMaterielTyperForMaterielTyp(ApplicationContext.Current.Val.Id, parentId).OrderBy(mt => mt.Beskrivning).ToList();
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetUnderliggandeMaterielTyp", "Error getting underliggande materieltyper", ex);
			}
			return result;
		}
		#endregion

		#region Funktion
		public Funktion GetFunktion(Guid id)
		{
			Funktion result = null;
			try
			{
				result = this.channel.GetFunktion(ApplicationContext.Current.Val.Id, id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetFunktion", "Error getting funktion", ex);
			}
			return result;
		}

		public Funktion[] GetFunktioner()
		{
			Funktion[] result = null;
			try
			{
				result = this.channel.GetFunktioner(ApplicationContext.Current.Val.Id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetFunktioner", "Error getting funktioner", ex);
			}
			return result;
		}

		public void CreateFunktion(Funktion funktion)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.CreateFunktion(funktion);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreateFunktion", "Error creating funktion", ex);
			}
		}

		public void UpdateFunktion(Funktion funktion)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.UpdateFunktion(funktion);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateFunktion", "Error updating funktion", ex);
			}
		}

		public void DeleteFunktion(Guid funktionId)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.DeleteFunktion(ApplicationContext.Current.Val.Id, funktionId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "DeleteFunktion", "Error deleting funktion", ex);
				throw;
			}
		}
		#endregion

		#region Grupp
		public Grupp GetGrupp(Guid id)
		{
			Grupp result = null;
			try
			{
				result = this.channel.GetGrupp(ApplicationContext.Current.Val.Id, id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetGrupp", "Error getting Grupp", ex);
			}
			return result;
		}

		public IEnumerable<Grupp> GruppSearch()
		{
			IEnumerable<Grupp> result = null;
			try
			{
				result = this.channel.GruppSearch(ApplicationContext.Current.Val.Id, null);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GruppSearch", "Error searching grupp", ex);
			}
			return result;
		}

		public void CreateGrupp(Grupp Grupp)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.CreateGrupp(Grupp);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreateGrupp", "Error creating grupp", ex);
			}
		}

		public void UpdateGrupp(Grupp Grupp)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.UpdateGrupp(Grupp);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateGrupp", "Error updating grupp", ex);
			}
		}

		public void DeleteGrupp(Guid GruppId)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.DeleteGrupp(ApplicationContext.Current.Val.Id, GruppId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "DeleteGrupp", "Error deleting grupp", ex);
				throw;
			}
		}
		#endregion

		#region PersonTyp
		public PersonTyp GetPersonTyp(Guid id)
		{
			PersonTyp result = null;
			try
			{
				result = this.channel.GetPersonTyp(ApplicationContext.Current.Val.Id, id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetPersonTyp", "Error getting PersonTyp", ex);
			}
			return result;
		}

		public IEnumerable<PersonTyp> GetPersonTyper()
		{
			IEnumerable<PersonTyp> result = null;
			try
			{
				result = this.channel.GetPersonTyper(ApplicationContext.Current.Val.Id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetPersonTyper", "Error getting PersonTyper", ex);
			}
			return result;
		}

		public void CreatePersonTyp(PersonTyp pt)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.CreatePersonTyp(pt);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreatePersonTyp", "Error creating PersonTyp", ex);
			}
		}

		public void UpdatePersonTyp(PersonTyp pt)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.UpdatePersonTyp(pt);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdatePersonTyp", "Error updating PersonTyp", ex);
			}
		}

		public void DeletePersonTyp(Guid ptId)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.DeletePersonTyp(ApplicationContext.Current.Val.Id, ptId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "DeletePersonTyp", "Error deleting PersonTyp", ex);
				throw;
			}
		}
		#endregion

        #region ByggnadTyp
        public ByggnadTyp GetByggnadTyp(Guid id)
		{
			ByggnadTyp result = null;
			try
			{
				result = this.channel.GetByggnadTyp(ApplicationContext.Current.Val.Id, id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetByggnadTyp", "Error getting ByggnadTyp", ex);
			}
			return result;
		}

		public IEnumerable<ByggnadTyp> GetByggnadTyper()
		{
			IEnumerable<ByggnadTyp> result = null;
			try
			{
				result = this.channel.GetByggnadTyper(ApplicationContext.Current.Val.Id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetByggnadTyper", "Error getting ByggnadTyper", ex);
			}
			return result;
		}

		public void CreateByggnadTyp(ByggnadTyp pt)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.CreateByggnadTyp(pt);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreateByggnadTyp", "Error creating ByggnadTyp", ex);
			}
		}

		public void UpdateByggnadTyp(ByggnadTyp pt)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.UpdateByggnadTyp(pt);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateByggnadTyp", "Error updating ByggnadTyp", ex);
			}
		}

		public void DeleteByggnadTyp(Guid ptId)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.DeleteByggnadTyp(ApplicationContext.Current.Val.Id, ptId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "DeleteByggnadTyp", "Error deleting ByggnadTyp", ex);
				throw;
			}
		}
		#endregion

		#region Stadsdel
		public Stadsdel GetStadsdel(Guid id)
		{
			Stadsdel result = null;
			try
			{
				result = this.channel.GetStadsdel(ApplicationContext.Current.Val.Id, id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetStadsdel", "Error getting stadsdel", ex);
			}
			return result;
		}

		public IEnumerable<Stadsdel> GetStadsdelar()
		{
			IEnumerable<Stadsdel> result = null;
			try
			{
				result = this.channel.GetStadsdelar(ApplicationContext.Current.Val.Id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetStadsdeler", "Error getting stadsdeler", ex);
			}
			return result;
		}

		public void CreateStadsdel(Stadsdel pt)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.CreateStadsdel(pt);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreateStadsdel", "Error creating stadsdel", ex);
			}
		}

		public void UpdateStadsdel(Stadsdel pt)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.UpdateStadsdel(pt);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateStadsdel", "Error updating stadsdel", ex);
			}
		}

		public void DeleteStadsdel(Guid ptId)
		{
			base.CheckWriteAllowed();

			try
			{
				this.channel.DeleteStadsdel(ApplicationContext.Current.Val.Id, ptId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "DeleteStadsdel", "Error deleting stadsdel", ex);
				throw;
			}
		}
		#endregion

		#region Val
		public Val GetVal(Guid id)
		{
			Val result = null;
			try
			{
				result = this.channel.GetVal(id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetVal", "Error getting val", ex);
			}
			return result;
		}

		public IEnumerable<Val> GetAllVal()
		{
			IEnumerable<Val> result = null;
			try
			{
				result = this.channel.GetAllVal();
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetAllVal", "Error getting alla val", ex);
			}
			return result;
		}

		public void CreateVal(Val newVal, Guid previousValId)
		{
			try
			{
				this.channel.CreateVal(newVal, previousValId);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "CreateVal", "Error creating val", ex);
                throw;
			}
		}

		public void UpdateVal(Val val)
		{
			try
			{
				this.channel.UpdateVal(val);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateVal", "Error updating val", ex);
				throw;
			}
		}
		#endregion

        #region Blankett
        public Blankett GetBlankett(Guid id)
        {
            Blankett result = null;
            try
            {
                result = this.channel.GetBlankett(ApplicationContext.Current.Val.Id, id);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetBlankett", "Error getting Blankett", ex);
            }
            return result;
        }

        public Blankett GetBlankettByName(string namn)
        {
            Blankett result = null;
            try
            {
                result = this.channel.GetBlankettByName(ApplicationContext.Current.Val.Id, namn);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetBlankettByName", "Error getting Blankett", ex);
            }
            return result;
        }

        public IEnumerable<Blankett> GetBlanketter()
        {
            IEnumerable<Blankett> result = null;
            try
            {
                result = this.channel.GetBlanketter(ApplicationContext.Current.Val.Id);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetBlanketter", "Error getting Blanketter", ex);
            }
            return result;
        }

        public void CreateBlankett(Blankett b)
        {
			base.CheckWriteAllowed();

            try
            {
                this.channel.CreateBlankett(b);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "CreateBlankett", "Error creating Blankett", ex);
            }
        }

        public void UpdateBlankett(Blankett b)
        {
			base.CheckWriteAllowed();

            try
            {
                this.channel.UpdateBlankett(b);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "UpdateBlankett", "Error updating Blankett", ex);
            }
        }

        public void DeleteBlankett(Guid bId)
        {
			base.CheckWriteAllowed();

            try
            {
                this.channel.DeleteBlankett(ApplicationContext.Current.Val.Id, bId);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "DeleteBlankett", "Error deleting Blankett", ex);
                throw;
            }
        }

        public void SetFaltForBlankett(Guid parentId, IEnumerable<BlankettFalt> blankettFalt)
        {
			base.CheckWriteAllowed();

            try
            {
                this.channel.SetFaltForBlankett(ApplicationContext.Current.Val.Id, parentId, blankettFalt);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "SetFaltForBlankett", "Error setting blankettFalt for blankett", ex);
				throw;
            }
        }

        public IEnumerable<Falt> GetFaltForBlankett(Guid blankettId)
        {
            IList<Falt> result = new List<Falt>();
            try
            {
                result = this.channel.GetFaltForBlankett(ApplicationContext.Current.Val.Id, blankettId).ToList();
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetFaltForBlankett", "Error getting falt for blankett", ex);
            }
            return result;
        }

        #endregion

        #region Falt
        public Falt GetFalt(Guid id)
        {
            Falt result = null;
            try
            {
                result = this.channel.GetFalt(ApplicationContext.Current.Val.Id, id);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetFalt", "Error getting Falt", ex);
            }
            return result;
        }

        public IEnumerable<Falt> GetAllaFalt()
        {
            IEnumerable<Falt> result = null;
            try
            {
                result = this.channel.GetAllaFalt(ApplicationContext.Current.Val.Id);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetAllaFalt", "Error getting AllaFalt", ex);
            }
            return result;
        }

        public void CreateFalt(Falt f)
        {
			base.CheckWriteAllowed();

            try
            {
                this.channel.CreateFalt(f);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "CreateFalt", "Error creating Falt", ex);
            }
        }

        public void UpdateFalt(Falt f)
        {
			base.CheckWriteAllowed();

            try
            {
                this.channel.UpdateFalt(f);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "UpdateFalt", "Error updating Falt", ex);
            }
        }

        public void DeleteFalt(Guid fId)
        {
			base.CheckWriteAllowed();

            try
            {
                this.channel.DeleteFalt(ApplicationContext.Current.Val.Id, fId);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "DeleteFalt", "Error deleting Falt", ex);
                throw;
            }
        }

        public void SetFaltAlternativForFalt(Guid faltId, IEnumerable<FaltAlternativ> faltAlternativ)
        {
            try
            {
                this.channel.SetFaltAlternativForFalt(ApplicationContext.Current.Val.Id, faltId, faltAlternativ);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "SetFaltAlternativForFalt", "Error setting faltAlternativ for falt", ex);
            }
        }

        public IEnumerable<FaltAlternativ> GetFaltAlternativForFalt(Guid faltId)
        {
            IList<FaltAlternativ> result = new List<FaltAlternativ>();
            try
            {
                result = this.channel.GetFaltAlternativForFalt(ApplicationContext.Current.Val.Id, faltId).OrderBy(f => f.Namn).ToList();
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetFaltAlternativForFalt", "Error getting faltalternativ for falt", ex);
            }
            return result;
        }
        #endregion

		#region Integrationer
		public IEnumerable<PersonData> GetPersonData()
		{
			IEnumerable<PersonData> result = new List<PersonData>();
			try
			{
				result = this.channel.GetPersonData(ApplicationContext.Current.Val.Id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetPersonData", "Error getting LISA data", ex);
				throw;
			}
			return result;
		}

		public IEnumerable<PersonData> GetPersonDataIntegration()
		{
			IEnumerable<PersonData> result = new List<PersonData>();
			try
			{
				result = this.channel.GetPersonDataIntegration(ApplicationContext.Current.Val.Id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetPersonDataIntegration", "Error getting integration data", ex);
				throw;
			}
			return result;
		}

		public IEnumerable<string> GetPersonnummerList()
		{
			IEnumerable<string> result = new List<string>();
			try
			{
				result = this.channel.GetPersonnummerList(ApplicationContext.Current.Val.Id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetPersonnummerList", "Error getting skatteverket-export data", ex);
			}
			return result;
		}

		public IEnumerable<Lokal> GetLokalData()
		{
			IEnumerable<Lokal> result = new List<Lokal>();
			try
			{
				result = this.channel.GetLokalData(ApplicationContext.Current.Val.Id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetLokalData", "Error getting lokaldata for integration", ex);
			}
			return result;
		}
		#endregion
	}
}
